define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'aacase/index/index' + location.search,
                    add_url: 'aacase/index/add',
                    del_url: 'aacase/index/del',
                    multi_url: 'aacase/index/multi',
                    import_url: 'aacase/index/import',
                    table: 'aa_case'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order', title: __('Order'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'startime', title: __('Startime'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'endtime', title: __('Endtime'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'desc', title: __('Desc'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'time', title: __('创建'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'count', title: __('数量')},
                        {field: 'files', title: __('Files'), operate: false, formatter: Table.api.formatter.files},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    title: __('报价单'),
                                    icon: 'fa fa-navicon',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'aacase/index/plogs'
                                },
                                {
                                    name: 'detail',
                                    title: __('上传文件'),
                                    icon: 'fa fa-arrow-up',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'aacase/index/files'
                                },
                                {
                                    name: 'detail',
                                    title: __('清空数据'),
                                    icon: 'fa fa-cut',
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    url: 'aacase/index/clearphoto',
                                    confirm: '确认清空数据？',
                                    success: function (data, ret) {

                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                            ]



                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },


        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },

        files: function () {
            Controller.api.bindevent();
        },

        plogs:function (){

            Table.api.init({
                extend: {}
            });

            var table1 = $("#table1");
            var ids=$("#ids").val();
            // 初始化表格
            table1.bootstrapTable({
                url: 'aacase/index/plogs?id='+ids,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                // 禁用搜索功能
                search: false, // 禁用搜索
                commonSearch: false,
                // 禁用分页功能
                pagination: false,
                // 添加数据加载成功回调函数
                onLoadSuccess: function(data) {
                    console.log('数据加载成功:', data);
                },
                columns: [[
                    {field: 'id', title: __('Id')},
                    {field: 'catefrolist_name', title: __('名称')},
                    {field: 'money', title: __('金额')},
                    {field: 'size', title: __('尺寸')},
                    {field: 'type', title: __('类型')}
                ]]
            });

            // 为表格绑定事件
            Table.api.bindevent(table1);
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
